#include <bits/stdc++.h>

using namespace std;
using ll = long long;

bool check(string s, int l, int r) {
	int c1 = 0, c2 = 0, c3 = 0;
	for (int i = l; i <= r; i++) {
		if (s[i] == '1') {
			c1++;
		} else if (s[i] == '2') {
			c2++;
		} else if (s[i] == '3') {
			c3++;
		}
	}
	return (c1 == c2 && c1 == c3 && c2 == c3);
}

int main() {
	int n;
	string s;
	cin >> n >> s;

	ll ans = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 3; j + i <= n; j += 3) {
			if (check(s, i, i + j - 1)) {
				ans++;
			}
		}
	}

	cout << ans << endl;
}